package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.ADUser;
import com.vne.skyemart.model.Article;
import com.vne.skyemart.service.ADUserService;

@Controller
@SessionAttributes
@RequestMapping("/aduser")
public class ADUserController {
	@Autowired
	private ADUserService adUserService;
	
	@RequestMapping(value = "/save",method = RequestMethod.POST)
	public ModelAndView saveADUser(@ModelAttribute(" aduser") ADUser adUser,BindingResult result) {
		adUserService.addADUser(adUser);
		return new ModelAndView("redirect:/aduser.html");
	}
	@RequestMapping(method = RequestMethod.GET)
	public String listArticles(Model model) {
		model.addAttribute("articles", adUserService.listADUser());

		return "articlesList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addArticle(@ModelAttribute("article") Article article,
			BindingResult result) {
		return new ModelAndView("addADUser");
	}
}
